<template>
    <div id="parts">
        <div class="operation">
            <el-button @click="insertList" class="slot-btn-top" type="primary" size="small">新增</el-button>
        </div>
        <el-table :data="dataList.slice((currentPage-1)*pagesize,currentPage*pagesize)" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="name" label="职位名称" sortable min-width="400"></el-table-column>
            <el-table-column prop="type" label="职位类别" sortable min-width="200"></el-table-column>
            <el-table-column prop="number" label="招聘人数" sortable min-width="110"></el-table-column>
            <el-table-column prop="time" label="发布时间" sortable min-width="170"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" width="100">
                <template slot-scope="scope">
                    <el-button @click="updateList(scope.row)" type="text" size="small">编辑</el-button>
                    <el-button @click="deleteList(scope.row)" type="text" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="dataList.length"></el-pagination>


        <!-- 任务说明 -->
        <el-dialog :title="dialogTitle" width="600px" center :visible.sync="isDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                <el-form-item label="职位名称"><el-input  v-model="dialogList.name"></el-input></el-form-item>
                <el-form-item label="职位类别"><el-input  v-model="dialogList.type"></el-input></el-form-item>
                <el-form-item label="招聘人数"><el-input  v-model="dialogList.number"></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button @click="submitList" type="primary">确 定</el-button>
            </div>
        </el-dialog>


    </div>
</template>

<script>
    export default {
        name: "recruitmentInfo",
        data() {
            return {
                tokenId: sessionStorage.getItem("tokenId"),
                currentPage: 1,
                pagesize: 10,
                tableHeight: document.documentElement.clientHeight - 170,
                dataList: [],

                isDialog:false,
                dialogTitle:'',
                dialogList:{
                    name:'',
                    type:'',
                    number:"",
                },
            };
        },
        created() {
            this.getData();
        },
        methods: {
            getData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/recruitmentinfo/query?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.dataList = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {_this.$message.error("加载失败！请重新加载...");})
            },

            insertList(){
                this.isDialog = true;
                this.dialogTitle = '新增';
                this.dialogList = {
                    name:'',
                    type:'',
                    number:"",
                };
            },
            updateList(row){
                this.isDialog = true;
                this.dialogTitle = '编辑';
                this.dialogList = row;
            },
            deleteList(row){
                let _this = this;
                this.$confirm('是否删除此招聘信息?', '提示', {confirmButtonClass: 'el-button--warning'}).then(() => {
                    _this.$http({
                        url: '/api/adscm/operation/recruitmentinfo/delete?id='+row.id+'&tokenId='+_this.tokenId,
                        method: 'post',
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                    }).then(function (res) {
                        if (res.data.statusCode == 200) {
                            _this.getData();
                        } else {
                            _this.$message.error(res.data.desc);
                        }
                    }).catch(function (catchres) {_this.$message.error("加载失败！请重新加载...");})
                }).catch(() => {});


            },
            submitList(){
                let _this = this,url;
                if (_this.dialogTitle === '新增') {
                    url = '/api/adscm/operation/recruitmentinfo/insert?tokenId=' + _this.tokenId;
                } else if (_this.dialogTitle === '编辑') {
                    url = '/api/adscm/operation/recruitmentinfo/update?tokenId=' + _this.tokenId;
                }


                console.log(url, _this.dialogList )

                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data: _this.dialogList,
                }).then(function (res) {

                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                        _this.getData();

                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })


            },


            handleSizeChange: function (size) {
                this.pagesize = size;
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
            },

        }
    }
</script>

<style scoped></style>
